<!-- 详细新闻 -->
<template>
  <div class="newsDetails">
    <!-- 标题 -->
    <div class="newsDetails__title">
      <h1>{{newsDetail.newsTitle}}</h1>
      <span>上传时间：[ {{newsDetail.newsTime}} ]</span>
      <span v-if="newsDetail.newsType == 'notice'">类型：通知</span>
      <span v-else-if="newsDetail.newsType == 'illness'">类型：疫情</span>
      <span v-else-if="newsDetail.newsType == 'news'">类型：新闻</span>
      <span v-else>类型：其他</span>
    </div>
    <!-- 内容 -->
    <div class="newsDetails__container">{{newsDetail.newsContent}}</div>
  </div>
</template>

<script>
import { findNewsById } from '../api/index';
import tools from '../utils';
export default {
  name: '',
  props: [''],
  data() {
    return {
      newsDetail: {},
      date: {},
    };
  },
  created() {
    this.getAllNews();
  },
  methods: {
    // 获取所有公告
    getAllNews() {
      let id = this.$route.query.id;
      if (id == null) {
        this.$router.push('/news');
      }
      findNewsById(id).then((res) => {
        if (res.code === 200) {
          res.data.newsTime = res.data.newsTime.split('T')[0];
          this.newsDetail = res.data;
        }
        console.log(this.newsDetail);
      });
    },
  },
};
</script>

<style scoped lang="scss">
.newsDetails {
  .newsDetails__title {
    padding: 0 220px;
    text-align: center;
    h1 {
      font-size: 34px;
      margin-top: 12px;
      margin-bottom: 10px;
    }
    span {
      display: inline-block;
      margin-right: 20px;
    }
  }
  .newsDetails__container {
    padding: 0 220px;
    min-height: 800px;
  }
}
</style>